import redis

from application.config import appSettings


class ExtRedis:
    """封装 Redis 缓存扩展"""

    def __init__(self):
        self.redis = redis.Redis.from_url(appSettings.redis_url, encoding='utf-8', decode_responses=True)

    def get(self, key):
        return self.redis.get(key)

    def set(self, key, value, ex=None):
        return self.redis.set(key, value, ex=ex)

    def delete(self, key):
        return self.redis.delete(key)

    def instance(self):
        return self.redis
